home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / lib / mathlib / libfft / TRY / r_speed2d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.9 KB  |  222 lines

  1. #include <stdio.h>
  2. #include <sys/time.h>
  3.  
  4. #include "fft.h"
  5. #include "constant.h"
  6.  
  7. /*
  8. *   Precision Dependant declarations
  9. */
  10.  
  11. #ifdef DOUBLE
  12.  
  13. typedef double this_type;
  14. typedef double this_half;
  15.  
  16. #define        TOLERANCE        DTOLERANCE
  17. #define        THIS_GEN        dgen_
  18. #define        THIS_FFTI        dfft2di
  19. #define        THIS_FFTUI        dfft2dui
  20. #define        THIS_SCAL        dscal2d
  21. #define        THIS_FFT        dfft2d
  22. #define        THIS_FFTU        dfft2du
  23.  
  24. #endif
  25.  
  26. #ifdef SINGLE
  27.  
  28. typedef float this_type;
  29. typedef float this_half;
  30.  
  31. #define        TOLERANCE        STOLERANCE
  32. #define        THIS_GEN        sgen_
  33. #define        THIS_FFTI        sfft2di
  34. #define        THIS_FFTUI        sfft2dui
  35. #define        THIS_SCAL        sscal2d
  36. #define        THIS_FFT        sfft2d
  37. #define        THIS_FFTU        sfft2du
  38.  
  39. #endif
  40.  
  41. /*    */
  42.  
  43. void inimat_();
  44. void GetArguments();
  45. void get_values();
  46.  
  47. int min_size, max_size, inc_size, size, size_x, size_y, ld;
  48. this_type *pa, *pSave, *pSaveU, *pt;
  49.  
  50. int is_timing;
  51.  
  52. static     long z_sec, z_usec;
  53. static int first_time = 1;
  54.  
  55. float second()
  56. {
  57.         struct timeval s_val;
  58.     struct timezone s_z;
  59.     float time;
  60.     long n_sec, n_usec;
  61.         gettimeofday(&s_val, &s_z);
  62.     n_sec = s_val.tv_sec;
  63.     n_usec = s_val.tv_usec;
  64.     if( first_time ) {
  65.         z_sec = n_sec;
  66.         z_usec = n_usec;
  67.         first_time =0;
  68.     }
  69.     time = (float)(n_sec-z_sec) + (float)(n_usec -z_usec) * 1.0E-6;
  70.     return( time );
  71. }
  72.  
  73. main(argc,argv)
  74. int argc;
  75. char *argv[];
  76. {
  77.     int i, j, k, n_total, is_wrong, nx, ny, inc, n_times, n_flops;
  78.     double x, y, t, emax;
  79.     this_half ratio;
  80.  
  81. /* ******************************************************* */
  82.     GetArguments( argc, argv);
  83. /* ******************************************************* */
  84.  
  85.     srandom( (123*getpid()) | 0x01);
  86.  
  87.     for( size=min_size ; size <= max_size ; size *= inc_size) { 
  88.  
  89.     nx = (size_x) ? size_x : size;
  90.     ny = (size_y) ? size_y : size;
  91.     ld = nx+2;
  92.     n_total = (ld)*ny;
  93.     pa = (this_type *)malloc( (n_total + 3* ny + nx + 4*FACTOR_SPACE) * sizeof(this_type));
  94.     if( !(pa) ) {
  95.         fprintf( stderr, "Could not allocate ... Exiting\n");
  96.         exit (-1);
  97.     }
  98.  
  99.     fflush(stdout);
  100.  
  101.     printf( "%4d  ", size);
  102.  
  103.     n_flops = (int) (5. * (double)(nx*ny)/2. * (log((double)(nx*ny))/log(2.) - 1.));
  104.     n_times = (int) (MAX_FLOPS / (double)n_flops);
  105.     if(n_times < 1) n_times =1;
  106.     ratio = 1./(double)(nx*ny);
  107. /* *******************************************************
  108. ******************************************************* */
  109.     pSave = pa + n_total;
  110.  
  111.     THIS_GEN(pa, &n_total);
  112. /* *******************************************************
  113.     timing PACKED
  114.     pSave = THIS_FFTI( nx,ny, pSave);
  115.  
  116.     t = second();
  117.     for ( i = 0 ; i < n_times ; i++)  {
  118.         is_wrong = THIS_FFT( -1, nx, ny, pa, (ld), pSave);
  119.         is_wrong = THIS_FFT(  1, nx, ny, pa, (ld), pSave);
  120.         THIS_SCAL( nx, ny, ratio, pa, ld);
  121.     }
  122.     t = second() - t;
  123.  
  124.       if( is_timing)
  125.         x = t / (double)(2*n_times);
  126.       else
  127.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  128.  
  129.     printf("%6.3e  ", x);
  130. ******************************************************* */
  131. /* *******************************************************
  132.     timing NOT SO PACKED
  133. ******************************************************* */
  134.     pSave = THIS_FFTUI( nx,ny, pSave);
  135.  
  136.     t = second();
  137.     for ( i = 0 ; i < n_times ; i++)  {
  138.         is_wrong = THIS_FFTU( -1, nx, ny, pa, (ld), pSave);
  139.         is_wrong = THIS_FFTU(  1, nx, ny, pa, (ld), pSave);
  140.         THIS_SCAL( nx, ny, ratio, pa, ld);
  141.     }
  142.     t = second() - t;
  143.  
  144.       if( is_timing)
  145.         x = t / (double)(2*n_times);
  146.       else
  147.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  148.  
  149.     printf("%6.3e  ", x);
  150. /* *******************************************************
  151. ******************************************************* */
  152.     printf("\n");
  153.     free(pa);
  154.     }
  155.     return (0);
  156. }
  157.  
  158. int is_random;
  159.  
  160. void GetArguments( argc, argv)
  161. int argc;
  162. char *argv[];
  163. {
  164.     int i, j, k;
  165.     int nerror = 0;
  166.  
  167. #define ON    1
  168.  
  169.     max_size = MAX_SIZE;
  170.     min_size = MIN_SIZE;
  171.     inc_size = INC_SIZE;
  172.  
  173.     is_timing = 0;
  174.     size_x = 0;
  175.     size_y = 0;
  176.  
  177. /* ******************************************************* */
  178.     for ( i = 1 ; (i < argc) && (nerror != ON) ; i ++ ) {
  179.     if( argv[i][0] == '-') {
  180.         switch ( argv[i][1]) {
  181.         case 'x' :
  182.         case 'X' :  
  183.                 if( i+1 > argc)
  184.                 nerror = ON;
  185.                 else
  186.                 size_x = atoi( argv[++i]);
  187.                 break;
  188.         case 'y' :
  189.         case 'Y' :  
  190.                 if( i+1 > argc)
  191.                 nerror = ON;
  192.                 else
  193.                 size_y = atoi( argv[++i]);
  194.                 break;
  195.         case 't' :
  196.         case 'T' :  
  197.                 is_timing = 1;
  198.                 break;
  199.         default  :  nerror = ON;
  200.         }
  201.     }
  202.     else {
  203.         if( i+1 > argc)
  204.         nerror = ON;
  205.         else { 
  206.         min_size = atoi( argv[i++]);
  207.         max_size = atoi( argv[i++]);
  208.         inc_size = atoi( argv[i]);
  209.         }
  210.     }
  211.     }
  212.     if( nerror == ON) {
  213.     fprintf( stderr, 
  214.         "Usage : %s [-p(arallel)] [n_trials]\n", argv[0]);
  215.     exit(-1);
  216.     }
  217.     if ( is_timing) 
  218.         fprintf( stderr, "Checking Performance   in Secs\n");
  219.     else
  220.         fprintf( stderr, "Checking Performance   in Mflops\n");
  221. }
  222.